<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 选中一段内容，点击按钮复制选中的内容。 -->
    <p id="text" onclick="copyText()">复制的一段文字</p>
    <button onclick="copyText()">copy</button>
    <script>
      function copyText() {
        //复制
        document.execCommand('copy')
        alert('复制成功')
      }
    </script>
  </body>
</html>
